home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 May / com_0505_1.iso / opensource / top10 / amc_install.exe / {app} / Scripts / MovieMeter (NL).ifs < prev    next >
Encoding:
Text File  |  2004-12-03  |  7.7 KB  |  255 lines

  1. // GETINFO SCRIPTING
  2. // MovieMeter.nl import script
  3.  
  4. (***************************************************
  5.  *  Movie importation script for:                  *
  6.  *      MovieMeter (NL), http://MovieMeter.nl/     *
  7.  *                                                 *
  8.  *  Now works with the new site !!                 *
  9.  *                                                 *
  10.  *  Written by JanC <amc-script@janc.cjb.net>      *
  11.  *  (partially based on other import scripts)      *
  12.  *   corrections by rolandb5@hotmail.com           *                                  *
  13.  *  For use with Ant Movie Catalog                 *
  14.  *  http://antp.be/software/moviecatalog           *
  15.  *                                                 *
  16.  ***************************************************)
  17.  
  18.  
  19. program MovieMeter;
  20.  
  21. var
  22.   MovieName: string;
  23.  
  24.  
  25. procedure AnalyzeMoviePage(Address: string);
  26. var
  27.   Page: TStringList;
  28.   Line, Value: string;
  29.   LineNr: Integer;
  30.   I: Integer;
  31.   BeginPos, EndPos: Integer;
  32. begin
  33.   // get movie page
  34.   Page := TStringList.Create;
  35.   Page.Text := GetPage(Address);
  36.  
  37.   // get URL
  38.   SetField(fieldURL, Address);
  39.  
  40.   // find line with titles & year
  41.   LineNr := 0;
  42.   repeat
  43.     LineNr := LineNr + 1;
  44.     Line := Page.GetString(LineNr);
  45.   until Pos('<p class="kop">', Line) > 0;
  46.   // get original(?) title
  47.   BeginPos := Pos('<p class="kop">', Line);
  48.   Delete(Line, 1, BeginPos-1);
  49.   BeginPos := Pos('<p class="kop">', Line) + Length('<p class="kop">');
  50.    EndPos := Pos('(', Line) - Length(' ');
  51.   Value := Copy(Line, BeginPos, EndPos - BeginPos);
  52.   HTMLDecode(Value);
  53.   SetField(fieldOriginalTitle, Value);
  54.   Delete(Line, 1, EndPos);
  55.  
  56.   // get year
  57.   BeginPos := Pos('(', Line) + Length('(');
  58.   EndPos := pos(')', Line);
  59.   Value := Copy(Line, BeginPos, EndPos - BeginPos);
  60.   HTMLDecode(Value);
  61.   SetField(fieldYear, Value);
  62.  
  63.   // get first alternative title???
  64.   LineNr := LineNr + 1;
  65.   Line := Page.GetString(LineNr);
  66.   BeginPos := Pos('Alternatieve titel:', Line) + Length('    Alternatieve titel:');
  67.     if BeginPos > 0 then begin
  68.     EndPos := pos('</b>', Line);
  69.     Value := Copy(Line, BeginPos, EndPos - BeginPos);
  70.     HTMLDecode(Value);
  71.     SetField(fieldTranslatedTitle, Value);
  72.   end;
  73.  
  74.   // find line with country, cat & length
  75.   repeat
  76.     LineNr := LineNr + 1;
  77.     Line := Page.GetString(LineNr);
  78.   until Pos('geregisseerd door', Line) > 0;
  79.   // get country
  80.   BeginPos := 1;
  81.   EndPos := Pos('<br>', Line);
  82.   Value := StringReplace(Copy(Line, BeginPos, EndPos - BeginPos), #9, '');
  83.   HTMLDecode(Value);
  84.   SetField(fieldCountry, Value);
  85.   Delete(Line, 1, EndPos + Length('<br>') - 1);
  86.   // get category
  87.   BeginPos := 1;
  88.   EndPos := Pos('<br>', Line);
  89.   Value := Copy(Line, BeginPos, EndPos - BeginPos);
  90.   HTMLDecode(Value);
  91.   SetField(fieldCategory, Value);
  92.   Delete(Line, 1, EndPos + Length('<br>') - 1);
  93.   // get length
  94.   BeginPos := 1;
  95.   EndPos := Pos(' minuten <br>', Line);
  96.   Value := Copy(Line, BeginPos, EndPos - BeginPos);
  97.   HTMLDecode(Value);
  98.   SetField(fieldLength, Value);
  99.  
  100.   // find line with director & actors
  101.   repeat
  102.     LineNr := LineNr + 1;
  103.     Line := Page.GetString(LineNr);
  104.   until Pos('<a href="?regisseur=', Line) > 0;
  105.   // get director
  106.   BeginPos := Pos('">', Line) + Length('">');
  107.   EndPos := Pos('</a>', Line);
  108.   Value := Copy(Line, BeginPos, EndPos - BeginPos);
  109.   HTMLDecode(Value);
  110.   SetField(fieldDirector, Value);
  111.   Delete(Line, 1, EndPos-1);
  112.   // get actors
  113.   BeginPos := Pos('<br>met ', Line) + Length('<br>met ');
  114.   EndPos := Pos('</p><p>', Line);
  115.   Value := StringReplace(Copy(Line, BeginPos, EndPos - BeginPos), #9, '');
  116.   HTMLDecode(Value);
  117.   SetField(fieldActors, Trim(Value));
  118.  
  119.   Value := '';
  120.   repeat
  121.     // get line with description
  122.  
  123.     LineNr := LineNr + 1;
  124.     Line := Page.GetString(LineNr);
  125.     if Pos('</p>', Line) = 0 then begin
  126.     Value := Value + Line;
  127.     end;
  128.     // get description
  129.  
  130.     if Pos('</p>', Line) > 0 then begin
  131.       BeginPos := 1;
  132.       EndPos := Pos('</p>', Line);
  133.       Value := Value + Copy(Line, BeginPos, EndPos - BeginPos);
  134.  
  135.     end;
  136.     HTMLDecode(Value);
  137.  
  138.   until Pos('</p>', Line) > 0;
  139.   Value := StringReplace(Value, #9, '');
  140.   SetField(fieldDescription, Value);
  141.   // find line with cover picture
  142.   repeat
  143.     LineNr := LineNr + 1;
  144.     Line := Page.GetString(LineNr);
  145.   until Pos('<img src="images/covers/', Line) > 0;
  146.   // get cover picture
  147.   BeginPos := Pos('<img src="', Line) + Length('<img src="');
  148.   EndPos := Pos('" ', Line);
  149.   Value := Copy(Line, BeginPos, EndPos - BeginPos);
  150.   GetPicture('http://www.moviemeter.nl/' + Value, False);
  151.  
  152.   // find line with rating
  153.   repeat
  154.     LineNr := LineNr + 1;
  155.     Line := Page.GetString(LineNr);
  156.   until Pos('<td class="stembody">', Line) > 0;
  157.   LineNr := LineNr + 1;
  158.   Line := Page.GetString(LineNr);
  159.   // get average rating (range 0.00-5.00 on the site, range 0-10 in AMC)
  160.   BeginPos := Pos('<br>', Line) + Length('<br>');
  161.   EndPos := Pos(' gemiddeld', Line);
  162.   Value := Copy(Line, BeginPos, EndPos - BeginPos);
  163.   I := StrToInt(Copy(Value, 1, 1), 0) * 100 + StrToInt(Copy(Value, 3, 2), 0);
  164.   Value := IntToStr(Round(I/50));
  165.   SetField(fieldRating, Value);
  166.  
  167.   DisplayResults;
  168.   Page.Free;
  169. end;
  170.  
  171.  
  172. procedure AnalyzeResultsPage(Address: string);
  173. var
  174.   Page: TStringList;
  175.   Line: string;
  176.   MovieAddress: string;
  177.   LineNr: Integer;
  178.   MovieTitle: string;
  179.   StartPos, EndPos: Integer;
  180. begin
  181.   // get results page
  182.   Page := TStringList.Create;
  183.   Page.Text := GetPage(Address);
  184.  
  185.   // get redirect javascript
  186.   Line := Page.GetString(Page.Count-1);
  187.  
  188.   // if only 1 movie found --> redirect to movie page
  189.   if Pos('location.replace("?film=', Line) <> 0 then begin
  190.     StartPos := Pos('?film=', Line);
  191.     EndPos := Pos('");</script>', Line);
  192.     MovieAddress := 'http://moviemeter.nl/' + Copy(Line, StartPos, EndPos - StartPos);
  193.     AnalyzeMoviePage(MovieAddress);
  194.   end
  195.   // more than 1 movie found
  196.   else if Pos('location.href = "?searchresults"', Line) <> 0 then begin
  197.     PickTreeClear;
  198.  
  199.     // get results page
  200.     Page.Text := GetPage('?searchresults');
  201.  
  202.     // find line with results
  203.     LineNr := 0;
  204.     repeat
  205.       LineNr := LineNr + 1;
  206.       Line := Page.GetString(LineNr);
  207.     until Pos('<!--m-->', Line) > 0;
  208.  
  209.     // find individual results delimited by <!--m--> & <!--n-->'
  210.     StartPos := Pos('<!--m-->', Line);
  211.     while StartPos > 0 do begin
  212.       Delete(Line, 1, StartPos-1);
  213.       StartPos := Pos('<!--m-->', Line) + Length('<!--m--><a href="');
  214.       EndPos := Pos('">', Line);
  215.       MovieAddress := Copy(Line, StartPos, EndPos - StartPos);
  216.      
  217.       StartPos := Pos('">', Line) + Length('"><b>');
  218.       EndPos := Pos('<br>', Line);
  219.       MovieTitle := Copy(Line, StartPos, EndPos - StartPos);
  220.       HTMLRemoveTags(MovieTitle);
  221.       HTMLDecode(Movietitle);
  222.      
  223.       PickTreeAdd(MovieTitle, 'http://www.moviemeter.nl/' + MovieAddress);
  224.      
  225.       Delete(Line, 1, EndPos-1);
  226.       StartPos := Pos('<!--m-->', Line);
  227.     end;
  228.  
  229.     // if user picks a movie from the results list, import movie details
  230.     if PickTreeExec(Address) then
  231.       AnalyzeMoviePage(Address);
  232.   end
  233.   // no movies found
  234.   else begin
  235.     ShowMessage('Geen zoekresultaat voor "'+MovieName+'".');
  236.   end;
  237.  
  238.   Page.Free;
  239. end;
  240.  
  241.  
  242. begin
  243.   if CheckVersion(3,4,0) then     // is this really the minimum version?
  244.   begin
  245.     MovieName := GetField(fieldOriginalTitle);
  246.     if MovieName = '' then
  247.       MovieName := GetField(fieldTranslatedTitle);
  248.     if Input('MovieMeter.nl Import', 'Geef de titel van de film:', MovieName) then
  249.     begin
  250.       AnalyzeResultsPage('http://moviemeter.nl/?search&q='+UrlEncode(MovieName));
  251.     end;
  252.   end else
  253.     ShowMessage('Dit script vereist een nieuwere versie van Ant Movie Catalog (minstens versie 3.4.0)');
  254. end.
  255.